로딩 중이에요... 🐣
[코담]
웹개발·실전 프로젝트·AI까지, 파이썬·장고의 모든것을 담아낸 강의와 개발 노트
6. 테스트코드 views | ✅ 저자: 이유정(박사)
test_views.py
proj/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("restaurant.urls")),
]
restaurant/urls.py
from django.urls import path
from .views import index
app_name = "restaurant"
urlpatterns = [
path("", index, name="index"),
]
views.py
from django.shortcuts import render
def index(request):
return render(request, "index.html")
restaurant/tests/test_views.py
from django.test import TestCase
class IndexViewTest(TestCase):
def test_index_view(self):
response = self.client.get("/")
self.assertEqual(response.status_code, 200)
# assertTemplateUsed 메서드
# 뷰(view)가 특정 템플릿을 사용하여 응답을 생성했는지를 검증하는 데 사용
self.assertTemplateUsed(response, "index.html")
정확한 템플릿이 사용되었는지를 검증